/*
 * @Description: 
 * @Author: changqing
 * @Date: 2021-08-30 16:53:27
 * @LastEditTime: 2021-08-30 16:55:16
 * @LastEditors: changqing
 * @Usage: 
 */
var { timer, interval,range,from,Subject } = require('rxjs'); 
var {sample,map} = require('rxjs/operators');

//sample取样的意思，可以传一个notifier的Observable，每个notifier有新事件发生时，sample就会在来源Observable上取最近一次发生的事件值

const notifier = new Subject();
const source = interval(1000);
source.pipe(
  sample(notifier)
).subscribe(data => {
  console.log(`${data}`);
});

setTimeout(() => notifier.next(), 1500);
// 0
setTimeout(() => notifier.next(), 1600);
// nothing
setTimeout(() => notifier.next(), 5000);
// 4